/**
 * 
 */
package com.gko100.service.impl;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.gko100.dao.UserDao;
import com.gko100.model.Administrator;
import com.gko100.model.User;
import com.gko100.service.UserManager;
import com.gko100.util.DateTimeUtil;

/**
 * @author Administrator
 *
 */
public class UserManagerImpl implements UserManager {

	private UserDao userDao;
	public UserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	/* 
	 * {见接口方法说明}
	 */
	public boolean logout(User user) {
		
		boolean flag = false;
		if(user!=null){
			
			user.setLogState("logout");
			userDao.update(user);
			flag = true;
		}
		return flag;
		
		
	}

	/* 
	 * {见接口方法说明}
	 */
	public boolean validLogin(User user) {
		
		boolean flag=false;
		User u = userDao.findUserByNameAndPass(user.getName(), user.getPassword());
		
		if(u!=null){	
			u.setLogState("login");
	        u.setLastSignDate(DateTimeUtil.getNowTime());
			userDao.update(u);
			flag=true;
		}
		return flag;
		
	}
	
	public User findUserByNameAndPassword(String name, String password){
		
		User u = userDao.findUserByNameAndPass(name, password);
		if(u!=null){
			return u;
		}else{
			return null;
		}

	}
	
	public User findUserByName(String name){
		
		User u = userDao.findUserByName(name);
		if(u!=null){
			return u;
		}else{
			return null;
		}
		
	}
	
	
	
	public void add_user(User user){
		
		System.out.println("user.getName()========="+user.getName());
		userDao.save(user);
	}

}
